// #ifdef APP-PLUS
import interceptorChooseImage from '@/uni_modules/json-interceptor-chooseImage/js_sdk/main.js';
// #endif
import store from '@/store'
//需要登录的页面
let list = ['/pages/tabBar/index']
const install = (app) => {
	// 路由拦截
	uni.addInterceptor('navigateTo', {
		invoke(args) {
			let index = args.url.indexOf('?') == -1 ? args.url.length : args.url.indexOf('?')
			let activeUrl = args.url.slice(0, index);
			let userInfo = store.userInfo
			let userToken = store.userToken
			//检测需要登录的页面
			if (list.includes(activeUrl) && !userInfo && !userToken) {
				uni.navigateTo({
					url: `/pages/user/login/login?from=${args.url}`,
					success: res => {
						// setTimeout(()=>{
						// 	uni.showToast({
						// 		title: '请先授权登录',
						// 		icon:'none'
						// 	});
						// },1000)
					},
					fail: () => {},
					complete: () => {}
				});
				return false;
			}
		},
		success(args, params) {
			// console.log('success',params);
		},
		fail(err) {
			// console.log('interceptor-fail', err)
		},
		complete(res) {
		}
	})
	// #ifdef APP-PLUS
	// 当选择图片遇到权限问题时引导用户快捷打开系统设置
	interceptorChooseImage()
	// #endif
}
export default {
	install
}